$.fn.editable.defaults.mode = 'inline';

$(".select2").select2();

function auditMsgFormatter(value, row, index) {
    if (value == "" || value == undefined)
        return value;
    if (value.length > 6) {
        return value.substr(0, 6) + "<a href=\"javascript:void(0)\" onclick=\"showTip('" + value + "')\"  \">......</a>";
    } else {
        return value;
    }
}

function scoreFormatter(value, row, index) {
    if (value == "0") {
        return "<button type=\"button\" class=\"btn btn-primary btn-xs\" onclick=\"showProductScoreModal('" + row.id + "')\">&nbsp;&nbsp;&nbsp;评分&nbsp;&nbsp;&nbsp;</button>"
    } else if(row.status == "0"){
        return "<a href='javascript:void(0)' onclick=\"showProductScoreModal('" + row.id + "')\" >&nbsp;&nbsp;&nbsp;" + value + "&nbsp;&nbsp;&nbsp;</a>";
    } else {
        return value;
    }

}

function manageNumFormatter(value, row, index) { 
	   // alert(row.manager);
	    //alert("<a href='javascript:void(0)' onclick=\"showmanageNumModal('" + row.manager +","+row.periodTime+ "')\" >&nbsp;&nbsp;&nbsp;" + value + "&nbsp;&nbsp;&nbsp;</a>");
        return "<a href='javascript:void(0)' onclick=\"showmanageNumModal('" + row.manager +"','"+row.periodTime+ "')\" >&nbsp;&nbsp;&nbsp;" + value + "&nbsp;&nbsp;&nbsp;</a>"; 
}

function manageTotalSzFormatter(value, row, index) {  
        return "<a href='javascript:void(0)' onclick=\"showmanageNumModal('" + row.manager +","+row.periodTime+  "')\" >&nbsp;&nbsp;&nbsp;" + value + "&nbsp;&nbsp;&nbsp;</a>";
}
function scoreDetailFormatter(value, row, index) {

        return "<button type=\"button\" class=\"btn btn-primary btn-xs\" onclick=\"showProductScoreModal('" + row.id + "')\">&nbsp;&nbsp;&nbsp;详情&nbsp;&nbsp;&nbsp;</button>"
   

}


function statusFormatter(value, row, index) {
    if (value == "0") {
        return "<span  class=\"label label-primary\">初始化</span>"
    } else if (value == "1") {
        return "<span  class=\"label label-info \">未评审</span>"
    } else if (value == "2") {
        return "<span  class=\"label label-info\">评审中</span>";
    } else if (value == "3") {
        return "<span  class=\"label label-success\">评审通过</span>";
    } else if (value == "4") {
        return "<span  class=\"label label-warning\">驳回</span>";
    } else if (value == "9") {
        return "<span  class=\"label bg-purple\">关闭</span>";
    }
}

function operateFormatter(value, row, index) {
    var html = "";
  // alert("value:"value);
    if (value == "0" || value == "4") {
       // html = html + "&nbsp;<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"operate('close','" + row.id + "')\">&nbsp;关闭&nbsp;</button>";
        html = html + "&nbsp;<button type=\"button\" class=\"btn btn-danger btn-xs\" onclick=\"operate('delete','" + row.id + "')\">&nbsp;删除&nbsp;</button>";
    }    
    if (value != "0" && value != "9") {
        html = html + "&nbsp;<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"infoCustScore('" + row.id + "')\">&nbsp;详情&nbsp;</button>";
    }
    return html;
}

function infoCustScore(custScoreId) {
    var url = "/scoreaudit/info/" + custScoreId;
    getReq(url, function (result) {
        if (result.success) {
            initInfoCustScoreModal(result.msg);
            $("#infoCustScoreModal").modal("show");
        } else {
            toastr['error'](result.msg, '提示');
        }
    });
}

function operate(operate, productScoreId) {
    if ("close" == operate) {
        toastr['success']('开发中', '提示');
        return;
    }
    var url = "/productscore/" + operate;
    var data = {
        id: productScoreId
    };
    //alert(operate);
    postReq(url, data, function (result) {
        if (result.success) {
            $("#custScoreT111able").bootstrapTable("refresh");
            toastr['success']('操作成功', '提示');
        } else {
            toastr['error'](result.msg, '提示');
        }
    })
}


function timeZonesFormatter(value, row, index) {
    var b = row.beginTime;
    var e = row.endTime;
    var bb = b.substr(0, 2) + ":" + b.substr(2, 2) + ":" + b.substr(4, 2);
    var ee = e.substr(0, 2) + ":" + e.substr(2, 2) + ":" + e.substr(4, 2);
    return bb + "~" + ee;
}



function attentionFormatter(value, row, index) {
    if (value == "0") {
        return "<button type=\"button\" class=\"btn btn-block btn-primary btn-xs\" onclick=\"attention(" + row.id + ")\">关注批次</button>";
    } else if (value == "1") {
        return "<button type=\"button\" class=\"btn btn-block btn-primary btn-xs\" onclick=\"attention(" + row.id + ")\">取消关注</button>";
    } else {
        return value;
    }
}


function modifyCustValue(tableId, id, type, newValue) {
    var $table = $("#" + tableId);
    var data = {};
    if ("1" == type) {
        data = {
            id: id,
            quotaValueId: newValue
        };
    } else {
        data = {
            id: id,
            factValue: newValue
        };
    }
    var url = "/productscore/detail/modify";
    postReq(url, data, function (result) {
        if (result.success) {
            var url = "/productscore/detailInfo/list?id=" + id;
            getReq(url, function (result) {
                var row = $table.bootstrapTable("getRowByUniqueId", id);
                row.score = result[0].score;
                row.quotaValueName = result[0].quotaValueName;
                $table.bootstrapTable('updateByUniqueId', {id: id, row: row});
                $("#custScoreTable").bootstrapTable("refresh");
                toastr['success']('更新成功', '提示');
            });

        } else {
            toastr['error'](result.msg, '提示');
        }
    });
}

function changeStatus(taskId) {
    var data = {
        taskId: taskId
    };
    postReq("/task/changeStatus", data, function (result) {
        if (result.success) {
            $('#taskTable').bootstrapTable('refresh');
            toastr['success']('操作成功', '提示');
        } else {
            toastr['error'](result.msg, '提示');
        }
    });
}


function audit(value) {
    $("#customerInfoModel").modal("show");
}

function showAddCustomerModal() {
    addCustModalInit();
    $("#addCustModal").modal("show");
}

function showAddProductScore() {
    addCustScoreModalInit();
    $("#addProductScoreModal").modal("show");
}

function showProductScoreModal(productScoreId) {
	//alert(productScoreId);
    editCommonModalInit(productScoreId);
    $("#editCommonModal").modal("show");
}
function showmanageNumModal(manager,periodTime) {
	//alert("11"+manager);
	//alert("22"+periodTime);
	managenumModalInit(manager,periodTime);
    $("#managenumModal").modal("show");
}

function showIndustryScoreModal(custScoreId, modelVersionId) {
    editIndustryModalInit(custScoreId, modelVersionId)
    $("#editIndustryModal").modal("show");
}

function commonModelVersionFormatter(value, row, index) {
    return "一级通用-" + row.commonModelVersionId;
}

function industryNameFormatter(value, row, index) {
    if(value == null || value == "" || value == undefined)
        return "-" ;
    return value + "-" + row.industryModelVersionId;
}